//
//  BiParamEngine.m
//  GottaWash
//
//  Created by bindu on 14-9-1.
//  Copyright (c) 2014年 QiHe. All rights reserved.
//

#import "BiParamEngine.h"

@implementation BiParamEngine
SINGLE_INSTANCE_IMPLEMENTION(BiParamEngine)

// apns用到
- (void)setDeviceToken:(NSString*)deviceToken
{
    if ([deviceToken isKindOfClass:[NSString class]])
    {
        [[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:USER_DEFAULT_DEVICE_TOKEN];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}
- (NSString*)getDeviceToken
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_DEVICE_TOKEN];
}
- (float)getOneBagPrice
{
    NSNumber * priceNum = [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_ONE_BAG_PRICE];
    if (nil == priceNum)
    {
        return 99;
    }
    else
    {
        return [priceNum floatValue];
    }
}
- (void)setOneBagPrice:(float)price
{
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithFloat:price] forKey:USER_DEFAULT_ONE_BAG_PRICE];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

// 衣物一级列表更新时间戳
- (void)setLevel1UpdateTime:(int)updateTime
{
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:updateTime] forKey:USER_DEFAULT_LEVEL1_UPDATE_TIME];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (int)getLevel1UpdateTime
{
    NSNumber * timeNum = [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_LEVEL1_UPDATE_TIME];
    if (nil == timeNum)
    {
        return 0;
    }
    else
    {
        return [timeNum intValue];
    }
}

// 衣物二级列表更新时间戳
- (void)setLevel2UpdateTime:(int)updateTime
{
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:updateTime] forKey:USER_DEFAULT_LEVEL2_UPDATE_TIME];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (int)getLevel2UpdateTime
{
    NSNumber * timeNum = [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_LEVEL2_UPDATE_TIME];
    if (nil == timeNum)
    {
        return 0;
    }
    else
    {
        return [timeNum intValue];
    }
}

// 衣物更新时间戳
- (void)setClothUpdateTime:(int)updateTime
{
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:updateTime] forKey:USER_DEFAULT_CLOTH_UPDATE_TIME];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (int)getClothUpdateTime
{
    NSNumber * timeNum = [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_CLOTH_UPDATE_TIME];
    if (nil == timeNum)
    {
        return 0;
    }
    else
    {
        return [timeNum intValue];
    }
}

// 地址一级列表更新时间戳
- (void)setLevel1AddressUpdateTime:(int)updateTime
{
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:updateTime] forKey:USER_DEFAULT_LEVEL1_ADDRESS_UPDATE_TIME];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (int)getLevel1AddressUpdateTime
{
    NSNumber * timeNum = [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_LEVEL1_ADDRESS_UPDATE_TIME];
    if (nil == timeNum)
    {
        return 0;
    }
    else
    {
        return [timeNum intValue];
    }
}

// 地址二级列表更新时间戳
- (void)setLevel2AddressUpdateTime:(int)updateTime
{
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:updateTime] forKey:USER_DEFAULT_LEVEL2_ADDRESS_UPDATE_TIME];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (int)getLevel2AddressUpdateTime
{
    NSNumber * timeNum = [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_LEVEL2_ADDRESS_UPDATE_TIME];
    if (nil == timeNum)
    {
        return 0;
    }
    else
    {
        return [timeNum intValue];
    }
}

// 选择的地址
- (BOOL)hasSelectAddressId
{
    NSNumber * number = [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_SELECTED_ADDRESS_ID];
    if (nil == number || number.intValue < 0)
    {
        return NO;
    }
    
    return YES;
}
- (int)getSelectAddressId
{
    NSNumber * number = [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_SELECTED_ADDRESS_ID];
    if (nil == number)
    {
        return -1;
    }
    else
    {
        return [number intValue];
    }
}
- (void)setSelectAddressId:(int)selectId
{
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:selectId] forKey:USER_DEFAULT_SELECTED_ADDRESS_ID];
}


- (NSString*)getPreviousPhone
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:USER_DEFAULT_PREVIOUS_PHONE];
}
- (void)setPreviousPhone:(NSString*)phone
{
    [[NSUserDefaults standardUserDefaults] setObject:phone forKey:USER_DEFAULT_PREVIOUS_PHONE];
}

@end
